package cn.iocoder.yudao.module.form.mysql;


import cn.iocoder.yudao.module.form.dataobject.FormTable;
import cn.iocoder.yudao.module.form.dataobject.FormTableColumn;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Mapper
public interface SelfFormMapper {
    @Select("SELECT TABLE_NAME, TABLE_ROWS, table_comment FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'ry-vue-pro-v2' AND create_time >= '2022-09-14'")
    List<FormTable> getTable();

    @Select("SELECT COLUMN_NAME,COLUMN_TYPE,DATA_TYPE,COLUMN_COMMENT FROM INFORMATION_SCHEMA.COLUMNS\n" +
            "where table_schema ='ry-vue-pro-v2' and TABLE_NAME = #{tableName}")
    List<FormTableColumn> getTableColumn(@Param("tableName") String tableName);


    @Select("SELECT ${Column} FROM ${tableName}")
    List<String> getDataByTableColumn(@Param("tableName") String tableName,
                                 @Param("Column") String Column);

    @Select("SELECT * FROM ${tableName}")
    List<Object> getDataByTable(@Param("tableName") String tableName);

    @Select("SELECT distinct ${Column} FROM ${tableName}")
    List<String> getDistinctDataByTableColumn(@Param("tableName") String tableName,
                                      @Param("Column") String Column);

    @Select("SELECT ${Column},sum(${Column2}) FROM ${tableName} group by ${Column} ORDER BY sum(${Column2}) DESC")
    List<Map> getDistinctSumColumn(@Param("tableName") String tableName,
                                               @Param("Column") String Column,
                                               @Param("Column2") String Column2);


    @Select("SELECT ${Column1} FROM ${tableName} where ${Column2}=#{para1} and ${Column3}=#{para2}")
    String getYByOneXManyRecord(@Param("tableName") String tableName,
                              @Param("Column1") String Column1,
                              @Param("Column2") String Column2,
                              @Param("Column3") String Column3,
                              @Param("para1") String para1,
                              @Param("para2") String para2);

}
